package 滑动窗口And双指针;

import org.junit.Test;

import java.util.*;

/**
 * @author aodre , QQ : 480029069
 * @date 2023/6/1 17:53
 */
public class 美团彩带 {


    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), k = sc.nextInt();
        int nums[] = new int[n];
        for(int i = 0;i < n;i++ ){
            nums[i] = sc.nextInt();
        }

//        Set<Integer> set = new HashSet<>();
        Map<Integer,Integer> map = new HashMap<>();
        int ans = 0;
        for(int l = 0, r = 0;r < n;){
            map.put(nums[r],map.getOrDefault(nums[r], 0 ) + 1);
            while(map.size() > k){
                int value;
                if((value = map.get(nums[l]) - 1) == 0){
                    map.remove(nums[l]);
                }else{
                    map.put(nums[l],value);
                }
                l++;
            }
            ans = Math.max(ans,r - l + 1);
            r++; // 其实 这可以直接放到  上面的
        }
        System.out.println(ans);
    }


    @Test
    public void test(){
        Set<Integer> set = new HashSet<>();
        set.add(20);
        System.out.println(set.size());
        boolean remove = set.remove(10);
        System.out.println(remove);
        System.out.println(set.size());
    }

}
